package com.agile.leetcode.queue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * @Author ChenZhangKun
 * @Date 2020/11/16 15:59
 */
public class BlockingQueueDemo {
    // 1 ArrayBlockingQueue 有界队列
}
class ArrayBlockingQueueDemo{
    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<Integer> arrayBlockingQueue=new ArrayBlockingQueue(10);
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                try {
                    System.out.println(arrayBlockingQueue.take());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(()->{
            for (int i = 0; i < 10; i++) {
                arrayBlockingQueue.add(i);
            }
        }).start();


    }
}
